package com.resou.reader.reader.v;

import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.media.Image;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.NavigationView;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.animation.AnimationUtils;
import android.widget.CheckBox;
import android.widget.CheckedTextView;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.sdk.android.feedback.impl.FeedbackAPI;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.resou.reader.R;
import com.resou.reader.ReSouApplication;
import com.resou.reader.api.entry.BookContentBean;
import com.resou.reader.api.entry.BookDetailBean;
import com.resou.reader.api.entry.ChapterItemBean;
import com.resou.reader.api.entry.ShareTimeBean;
import com.resou.reader.base.v.BaseActivity;
import com.resou.reader.bookdetail.BookDetailActivity;
import com.resou.reader.bookdetail.adapter.CatalogueAdapter;
import com.resou.reader.bookshelf.listener.OnItemClickListener;
import com.resou.reader.bookshelf.readhistory.datasupport.BookCollection;
import com.resou.reader.bookshelf.readhistory.datasupport.ReaderHistory;
import com.resou.reader.commom.Constant;
import com.resou.reader.mine.IView.UserInstance;
import com.resou.reader.reader.adpter.ReadBgAdapter;
import com.resou.reader.reader.animation.BaseAnimation;
import com.resou.reader.reader.animation.CoverAnimation;
import com.resou.reader.reader.animation.NoAnimation;
import com.resou.reader.reader.animation.RealAnimation;
import com.resou.reader.reader.animation.SlideAnimation;
import com.resou.reader.reader.m.SimpleAnimatorListener;
import com.resou.reader.reader.manager.PageFactory;
import com.resou.reader.reader.p.ReaderPresenter;
import com.resou.reader.reader.subsidy.SubSidyActivity;
import com.resou.reader.reader.utils.ScreenUtils;
import com.resou.reader.reader.utils.SpUtils;
import com.resou.reader.reader.utils.ViewUtils;
import com.resou.reader.reader.view.BookUnShelfView;
import com.resou.reader.reader.view.CatalogScrollerViewProvider;
import com.resou.reader.reader.view.CollectionHintFragment;
import com.resou.reader.reader.view.NativeTTAdView;
import com.resou.reader.reader.view.NoNetworkView;
import com.resou.reader.reader.view.PageView;
import com.resou.reader.reader.view.PayChapterView;
import com.resou.reader.reader.view.PopupWindowView;
import com.resou.reader.utils.DateUtil;
import com.resou.reader.utils.DateUtils;
import com.resou.reader.utils.DeviceUtils;
import com.resou.reader.utils.NetworkUtils;
import com.resou.reader.utils.PreferenceUtil;
import com.resou.reader.utils.StatusBarCompat;
import com.resou.reader.utils.ToastUtil;
import com.resou.reader.utils.UIHelper;
import com.resou.reader.view.Loading;
import com.resou.reader.view.recyclerviewfastscroll.FastScroller;
import com.umeng.analytics.MobclickAgent;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.resou.reader.commom.Constant.EXTRA_TO_ISJPUSH;
import static com.resou.reader.commom.Constant.EXTRA_TO_READER_FROM;

/**
 * ReaderActivity的启动来源于：书架、历史、书籍详情、目录
 */
public class ReaderActivity extends BaseActivity<ReaderPresenter> implements IReaderView, PopupWindowView.OnPopupWindowClickListener, BaseQuickAdapter.OnItemClickListener, View.OnTouchListener {
    private static final String TAG = "调试.ReaderActivity-App";
    private static final int ANIM_DURATION = 300;
    public static Integer[] BG_COLOR = {0xFFF7F3EF, 0xFFd8c9aa, 0xFFcce8cf, 0xFFb69b94, 0xFFd1b595};//白，黄，绿，红
    public static int[] BG_SPACE = {70, 50, 30};
    public static int MIN_TEXT_SIZE;
    public static int MAX_TEXT_SIZE;
    public static int DEFAULT_TEXT_SIZE;
    public static int MIN_SPACE_SIZE;
    public static int MAX_SPACE_SIZE;

    private static final int MSG_ENTER = 0;//进入动画
    private static final int MSG_EXIT = 1;//退出动画

    private static final int STATE_HIDE = 0;//隐藏
    private static final int STATE_SHOW = 1;//展示
    private static final int STATE_HIDING = 2;//正在隐藏
    private static final int STATE_SHOWING = 3;//正在展示
    @BindView(R.id.fastScroller)
    FastScroller fastScroller;
    @BindView(R.id.tvBookTitle)
    TextView tvBookTitle;
    @BindView(R.id.tvChapterState)
    TextView tvChapterState;
    @BindView(R.id.rlChapter)
    RelativeLayout rlChapter;
    private int layoutState = STATE_HIDE;//上下layout的隐藏状态
    @BindView(R.id.rlReadGuide)
    ImageView rlReadGuide;
    @BindView(R.id.tvChapterName)
    TextView tvChapterName;
    @BindView(R.id.rlChapterName)
    RelativeLayout rlChapterName;
    @BindView(R.id.tvPersent)
    TextView tvPersent;
    @BindView(R.id.rvReadBg)
    RecyclerView rvReadBg;
    @BindView(R.id.drawer_layout)
    DrawerLayout mDrawerLayout;
    @BindView(R.id.navigation)
    NavigationView mNavigationView;
    @BindView(R.id.reader_catalogue_recycler)
    RecyclerView mRecyclerView;
    @BindView(R.id.title_layout)
    RelativeLayout mTitleLayout;
    @BindView(R.id.bottom_layout)
    RelativeLayout mBottomLayout;
    @BindView(R.id.llBottomSet)
    LinearLayout llBottomSet;
    @BindView(R.id.coordinator)
    CoordinatorLayout mCoordinatorLayout;
    @BindView(R.id.seekBar)
    SeekBar mSeekBar;
    @BindView(R.id.tvSysLight)
    CheckedTextView tvSysLight;
    @BindView(R.id.page_view)
    PageView mPageView;
    @BindView(R.id.setting_parent)
    LinearLayout mSettingParent;
    @BindView(R.id.back_image)
    ImageView mBackImage;
    @BindView(R.id.tvAddShelf)
    TextView tvAddShelf;//加入书架
    @BindView(R.id.pre_chapter_text)
    TextView mPreChapterText;
    @BindView(R.id.next_chapter_text)
    TextView mNextChapterText;
    @BindView(R.id.catalogue_text)
    TextView mCatalogueText;
    @BindView(R.id.day_night_text)
    TextView mDayNightText;
    @BindView(R.id.setting_text)
    TextView mSettingText;
    @BindView(R.id.comment_text)
    TextView mCommentText;
    @BindView(R.id.light_seek)
    SeekBar mLightSeekBar;
    @BindView(R.id.order_btn)
    ImageView mOrderText;
    @BindView(R.id.tvProtectEye)
    TextView tvProtectEye;
    @BindView(R.id.ivMore)
    ImageView ivMore;
    int startProgress = 0;//启动时进度
    int endProgress = 0;//结束时进度
    BaseAnimation animation;

    //    Loading loading = null;
    private Receiver receiver = new Receiver();
    private IntentFilter intentFilter = new IntentFilter();
    private ReadBgAdapter readBgAdapter;
    PayChapterView mPayChapterView;
    /**
     * 广告控件
     */
    @BindView(R.id.nativeTTAdView)
    NativeTTAdView mNativeTTAdView;


    /**
     * 补贴模块
     */
    @BindView(R.id.tvMoney)
    TextView tvMoney;//补贴金额/zs/getZsBookId
    @BindView(R.id.tvOpenSubSidy)
    TextView tvOpenSubSidy;//开启补贴模式
    @BindView(R.id.tvSubSidyModel)
    TextView tvSubSidyModel;//开启补贴模式
    @BindView(R.id.rlSubSidy)
    RelativeLayout rlSubSidy;//右上角补贴容器
    @BindView(R.id.tvAddMoney)
    TextView tvAddMoney;//添加补贴金额
    AlertDialog alertDialogProgress;
    /**
     * 开启补贴模式的弹框
     */
    AlertDialog alertDialog = null;
    TextView tvDialogTitle;
    TextView tvOk;
    LinearLayout llExit;
    TextView tvContent;
    TextView tvCancelExit;
    TextView tvOkExit;
    View view = null;

    /**
     * 广告显示倒计时
     */
    @BindView(R.id.tvTime)
    TextView tvTime;

    AlertDialog alertShareDialog;
    CountDownTimer countDownTimer;
    int shareTime;//分享时间间隔
    private PageFactory mPageFactory;
    BookDetailBean bookDetailBean;
    BookCollection bookCollection;

    private boolean isCollection = false;
    private boolean isJush = false;

    @Override
    public int getLayoutId() {
        return R.layout.activity_reader;
    }

    @Override
    protected void initPresenter() {
        int from = getIntent().getIntExtra(Constant.EXTRA_TO_READER_FROM, Constant.START_FROM_BOOK_DETAIL);
        if (from == Constant.START_FROM_BOOK_DETAIL) {
            bookDetailBean = (BookDetailBean) getIntent().getParcelableExtra(Constant.EXTRA_BOOK_DETAIL_BEAN);
            if (bookDetailBean == null) {
                Log.e(TAG, "bookDetailBean is null");
                return;
            }
            presenter = new ReaderPresenter(this, this, bookDetailBean,
                    getIntent().getBooleanExtra(Constant.EXTRA_TO_NEW_CHAPTER, false));
        } else if (from == Constant.START_FROM_COLLECTION) {
            presenter = new ReaderPresenter(this, this, (BookCollection) getIntent().getParcelableExtra(Constant.EXTRA_COLLECTION_BEAN));
            isCollection = getIntent().getBooleanExtra("isCollection", false);
            isJush = getIntent().getBooleanExtra(EXTRA_TO_ISJPUSH, false);
            Log.i("HomeBookShelfFragment", "initPresenter: " + isJush);
            bookCollection = (BookCollection) ((BookCollection) getIntent().getParcelableExtra(Constant.EXTRA_COLLECTION_BEAN));
            bookCollection.setCategoryName("2");
        } else if (from == Constant.START_FROM_CATALOGE) {
            presenter = new ReaderPresenter(this, this, (ChapterItemBean) getIntent().getParcelableExtra(Constant.EXTRA_CHAPTER_ITEM_BEAN), getIntent().getStringExtra(Constant.EXTRA_CATALOGUE_LAST_CHAPTER));
        } else {
            presenter = new ReaderPresenter(this, this, (ReaderHistory) getIntent().getParcelableExtra(Constant.EXTRA_READ_HISTORY_BEAN));
        }
    }

    @Override
    protected void initView() {
        if (!intentFilter.hasAction(Intent.ACTION_BATTERY_CHANGED)) {
            intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
        }
        if (!intentFilter.hasAction(Intent.ACTION_TIME_TICK)) {
            intentFilter.addAction(Intent.ACTION_TIME_TICK);
        }
        registerReceiver(receiver, intentFilter);

//        loading = Loading.getInstance();
        if (presenter.getChapterList().size() == 0) {
            Loading.getInstance().setView(2);
            Loading.getInstance().show(getSupportFragmentManager());
        }

        if (PreferenceUtil.getInstance(getApplicationContext()).getReadGuide()) {
            ViewUtils.getIMGToBitmap(getApplicationContext(), R.mipmap.read_guide_bg, rlReadGuide);
            rlReadGuide.setVisibility(View.VISIBLE);
        } else {
            rlReadGuide.setVisibility(View.GONE);
        }
        initDialog();
        initShareDialog();
        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }
//        getSupportFragmentManager().beginTransaction().add(R.id.coordinator, loading).hide(loading).commitAllowingStateLoss();
        MIN_TEXT_SIZE = UIHelper.sp2px(this, 10);
        MAX_TEXT_SIZE = UIHelper.sp2px(this, 40);
        MIN_SPACE_SIZE = UIHelper.sp2px(this, 6);
        MAX_SPACE_SIZE = UIHelper.sp2px(this, 38);
        DEFAULT_TEXT_SIZE = UIHelper.sp2px(this, 17);
        if (presenter == null) {
            initPresenter();
        }
        mSeekBar.setMax(presenter.getChapterNum() - 1);
        mSeekBar.setProgress(presenter.getDesChapterIndex());
//        mLightSeekBar.setMax(50);

        /** 设置 */
        /** 亮度设置 */
        int brightness = 1;
        boolean isSystemBirghtness = PreferenceUtil.getInstance(this).getIsSystemBirghtness();
        Log.i(TAG, "initView: " + isSystemBirghtness);
        tvSysLight.setChecked(isSystemBirghtness);
        if (isSystemBirghtness) {
            brightness = ScreenUtils.getSystemBrightness(this);
        } else {
            brightness = PreferenceUtil.getInstance(this).getBrightness(this);
            ScreenUtils.setActivityBrightness(this, brightness);
        }
        mLightSeekBar.setProgress(brightness - 1);
//        int progress = SpUtils.getReadLight(this, -1);
//        int sysProgress = ScreenUtils.getSystemBrightness(this);
//        if (progress >= 0) {
//            mLightSeekBar.setProgress(progress);
//            ScreenUtils.changeAppBrightness(ReaderActivity.this, (progress / 100.0f) * 255.0f);
//        } else {
//            mLightSeekBar.setProgress((int) ((sysProgress / 255.0f) * 100));
//            ScreenUtils.changeAppBrightness(ReaderActivity.this, sysProgress);
//        }
        if (SpUtils.getProtectEye(getApplicationContext())) {
            tvProtectEye.setSelected(true);
            tvMoney.setTextColor(getResources().getColor(R.color.colorFF7E2A));
        } else {
            tvProtectEye.setSelected(false);
            tvMoney.setTextColor(getResources().getColor(R.color.colorffff7c25));
        }
        mTitleLayout.setTranslationY(-mTitleLayout.getLayoutParams().height);
        mBottomLayout.setTranslationY(mBottomLayout.getLayoutParams().height);
        mSettingParent.setTranslationY(mSettingParent.getLayoutParams().height);
        mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
        tvBookTitle.setText(presenter.getBookName());
        tvChapterState.setText("共" + String.valueOf(presenter.getChapterNum()) + "章");
        LinearLayoutManager layoutManager = new LinearLayoutManager(ReaderActivity.this, LinearLayoutManager.VERTICAL, false);
        mRecyclerView.setLayoutManager(layoutManager);
        mRecyclerView.setAdapter(mAdapter);
        fastScroller.setRecyclerView(mRecyclerView);
        fastScroller.setViewProvider(new CatalogScrollerViewProvider(this));
        rvReadBg.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
        mDrawerLayout.addDrawerListener(new DrawerLayout.DrawerListener() {
            @Override
            public void onDrawerSlide(@NonNull View view, float v) {

            }

            @Override
            public void onDrawerOpened(@NonNull View view) {
                mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
                int visibleChildCount;
                visibleChildCount = layoutManager.findLastVisibleItemPosition() - layoutManager.findFirstVisibleItemPosition();
                mAdapter.scroollToPosition(mRecyclerView, visibleChildCount);
            }

            @Override
            public void onDrawerClosed(@NonNull View view) {
                mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
                mPageView.setCanPage(true);
            }

            @Override
            public void onDrawerStateChanged(int i) {
            }
        });

        mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                endProgress = seekBar.getProgress();
                if (layoutState == STATE_SHOW) {
                    rlChapterName.setVisibility(View.VISIBLE);
                    tvChapterName.setText(presenter.getChapterName(progress));
                    tvPersent.setText(presenter.getPersentValue(progress) + "%");
                }
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                startProgress = seekBar.getProgress();
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
//                showLoading("");
//                loading.show(getSupportFragmentManager());
                Loading.getInstance().show(getSupportFragmentManager());
//                PreferenceUtil.getInstance(ReaderActivity.this).saveAdValue(presenter.getBookId(), 1001);
                endProgress = seekBar.getProgress();
                mPageFactory.startChapterFromBegin();
                mPageFactory.toSpecifyChapter(seekBar.getProgress(), false);
                mPageView.refresh();
            }
        });

        mLightSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
//                ScreenUtils.changeAppBrightness(ReaderActivity.this, (progress / 100.0f) * 255.0f);
//                SpUtils.setReadLight(ReaderActivity.this, progress);
                ScreenUtils.setActivityBrightness(ReaderActivity.this, progress + 1);
                Log.i(TAG, "onProgressChanged: " + (progress + 1));
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                if (tvSysLight.isChecked()) {
//                    checkBox.setOnCheckedChangeListener(null);
                    tvSysLight.setChecked(false);
//                    menuSwitchBrightnessSystem.setOnCheckedChangeListener(ReaderActivity.this);
                    PreferenceUtil.getInstance(ReSouApplication.getRSApplication()).setIsSystemBirghtness(false);
                }
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                PreferenceUtil.getInstance(ReSouApplication.getRSApplication()).setBrightness(seekBar.getProgress() + 1);
            }
        });
        mSettingParent.setOnTouchListener(this);
        mBottomLayout.setOnTouchListener(this);
        mTitleLayout.setOnTouchListener(this);
        tvMoney.setOnTouchListener(this);
        tvOpenSubSidy.setOnTouchListener(this);

    }

    @Override
    protected void retryRefreshData() {

    }

    private LinearLayoutManager layoutManager;

    @SuppressLint("InflateParams")
    private void initSetting() {
        mPayChapterView = new PayChapterView(getApplicationContext());
        mPageFactory.setPayView(mPayChapterView);
        int textSize = SpUtils.getTextSize(this, DEFAULT_TEXT_SIZE);
        mPageFactory.setTextSize(textSize);
        Log.i(TAG, "initSetting: " + SpUtils.getSpaceTimes(this));
        mPageFactory.setSpace(SpUtils.getSpaceTimes(this));
        List bgList = Arrays.asList(BG_COLOR);
        if (readBgAdapter == null)
            readBgAdapter = new ReadBgAdapter(bgList);
        rvReadBg.setAdapter(readBgAdapter);
        rvReadBg.setHasFixedSize(true);
        readBgAdapter.setSelect(SpUtils.getBgIndex(this));
        readBgAdapter.setOnItemClickListener(this);
        mPageView.onBackgroundChange(BG_COLOR[SpUtils.getBgIndex(this)]);

        setTheme(SpUtils.getTheme(this));
        //设置适配器选中的目标
        layoutManager = (LinearLayoutManager) mRecyclerView.getLayoutManager();
        int visibleChildCount = 0;
        if (layoutManager != null) {
            visibleChildCount = layoutManager.findLastVisibleItemPosition() - layoutManager.findFirstVisibleItemPosition();
        }
        mAdapter.setSelectedItem(mPageFactory.getChapterIndex());
        mRecyclerView.scrollToPosition(Math.min(mPageFactory.getChapterIndex() + visibleChildCount - 1, presenter.getChapterNum() - 1));
        mPageFactory.setOnAdVisiableListener(new PageFactory.OnAdVisiableListener() {
            @Override
            public void setOnAdShow() {
                if (null != mNativeTTAdView) {
                    mNativeTTAdView.setClickableOnclick(true);
                }
            }

            @Override
            public void setOnAdHidden() {
                if (null != mNativeTTAdView) {
                    mNativeTTAdView.setClickableOnclick(false);
                }
            }
        });
    }

    @Override
    public void initPageView(PageFactory pageFactory) {
        mNativeTTAdView.setY(UIHelper.getInstance(this).getmScreenHeight());
        mPageFactory = pageFactory;
        mPageFactory.createAdView(mNativeTTAdView);
        mPageFactory.createUnShelfView(new BookUnShelfView(this));
        mPageFactory.createNoNetworkView(new NoNetworkView(this));
        int index = SpUtils.getAnimIndex(this);
        switch (index) {
            case 0:
                animation = new RealAnimation(this);
                selectView(findViewById(R.id.btn_real_anim));
                break;
            case 1:
                animation = new CoverAnimation();
                selectView(findViewById(R.id.btn_cover_anim));
                break;
            case 2:
                animation = new SlideAnimation();
                selectView(findViewById(R.id.btn_slide_anim));
                break;
            case 3:
            default:
                animation = new NoAnimation();
                selectView(findViewById(R.id.btn_no_anim));
                break;
        }
        mPageView.init(animation, mPageFactory);//翻页动画
        initSetting();
    }

    @Override
    public void errorBook() {
        ToastUtil.makeShortToast("该书籍存在异常，请阅读其他书籍");
        finish();
    }

    @Override
    public void refreshPageView() {
        mPageView.refreshCurrPage();
        mPageView.refreshNextPage();
    }

    @Override
    public void refreshPayView() {
        mPageFactory.initPayView();
        mPageView.refresh();
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {

        int screenWidth = ScreenUtils.getScreenWidth();
        int screenHeight = ScreenUtils.getScreenHeight();
        float x = ev.getX();
        float y = ev.getY();
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                if (!isShow() && mSettingParent.getTranslationY() != 0 && !mDrawerLayout.isDrawerOpen(mNavigationView)
                        && y < screenHeight * 2 / 3 && x > screenWidth / 3 && x < screenWidth * 2 / 3) {
                    mPageView.setCanPage(false);
                    tvTime.setVisibility(View.GONE);
                }
                if (isShow() || mSettingParent.getTranslationY() == 0 || mDrawerLayout.isDrawerOpen(mNavigationView)) {
                    mPageView.setCanPage(false);
                    tvTime.setVisibility(View.GONE);
                }
                break;
            case MotionEvent.ACTION_UP:
                if (mSettingParent.getTranslationY() == 0 && y < (screenHeight - mSettingParent.getLayoutParams().height)) {
                    dismissSettingLayout();
                    mPageView.setCanPage(true);
                    if (0 < shareTime && shareTime <= 20 && mPageFactory.isSubSidyState()) {
                        tvTime.setVisibility(View.VISIBLE);
                    }
                } else if (isShow() && y > ivMore.getHeight() + 40 && y < (screenHeight - mBottomLayout.getHeight())) {
                    dismiss();
                    mPageView.setCanPage(true);
                    if (0 < shareTime && shareTime <= 20 && mPageFactory.isSubSidyState()) {
                        tvTime.setVisibility(View.VISIBLE);
                    }
                } else {
                    if (!mDrawerLayout.isDrawerOpen(mNavigationView) && mSettingParent.getTranslationY() != 0) {
                        if (y < screenHeight * 2 / 3 && x > screenWidth / 3 && x < screenWidth * 2 / 3 && !mPageView.isCanPage()) {
                            /**
                             * 避免点击重新获取弹出菜单框
                             */
                            if (!mPageFactory.refreshUnshelfData(ev) && presenter.isCacheChapterList()) {
                                show();
                            }
                            mPageView.setCanPage(false);
                            tvTime.setVisibility(View.GONE);
                        } else if (y > ivMore.getHeight() + 40 && y < (screenHeight - llBottomSet.getHeight())) {
                            mPageView.setCanPage(true);
                            dismiss();
                            if (0 < shareTime && shareTime <= 20 && mPageFactory.isSubSidyState()) {
                                tvTime.setVisibility(View.VISIBLE);
                            }
                        } else {
                            mPageView.setCanPage(true);
                            if (0 < shareTime && shareTime <= 20 && mPageFactory.isSubSidyState()) {
                                tvTime.setVisibility(View.VISIBLE);
                            }
                        }
                    }
                }
                break;
        }
        return super.dispatchTouchEvent(ev);
    }

    @Override
    public void showLoading(String text) {
//        loading.setLoadingText(text);
//        if (!loading.isShow()) {
////            getSupportFragmentManager().beginTransaction().show(loading).commitAllowingStateLoss();
//        }
//        isCliable = false;
        showLoading();
    }

    @Override
    public void dismissLoading() {
//        getSupportFragmentManager().beginTransaction().hide(loading).commitAllowingStateLoss();
//        if (loading.isShow()) {
//            loading.dismiss();
//        }

        new CountDownTimer(1000, 100) {
            @Override
            public void onTick(long millisUntilFinished) {

            }

            @Override
            public void onFinish() {
                dissLoading();
                if (mPageFactory != null && mPageFactory.isSubSidyState()) {
                    if (tvMoney != null) {
                        tvMoney.setVisibility(View.VISIBLE);
                    }
                }
            }
        }.start();
    }

    @Override
    public void onChapterChanged(int chapterIndex) {
        Log.i(TAG, "onChapterChanged: " + chapterIndex);
        //根据用户跳转的章节来更新界面
        mSeekBar.setProgress(chapterIndex);
        LinearLayoutManager layoutManager = (LinearLayoutManager) mRecyclerView.getLayoutManager();
        int visibleChildCount = 0;
        if (layoutManager != null) {
            visibleChildCount = layoutManager.findLastVisibleItemPosition() - layoutManager.findFirstVisibleItemPosition();
        }

        //设置适配器选中的目标
        mAdapter.setSelectedItem(mPageFactory.getChapterIndex());
        if (startProgress < endProgress) {
            mRecyclerView.scrollToPosition(Math.min(mPageFactory.getChapterIndex() + visibleChildCount - 1, presenter.getChapterNum() - 1));
        } else {
            mRecyclerView.scrollToPosition(mPageFactory.getChapterIndex());
        }
        startProgress = mSeekBar.getProgress();
//        dismissLoading();

    }

    @Override
    public boolean isfromCollect() {
        return isCollection;
    }

    @Override
    public boolean isfromJush() {
        return isJush;
    }

    @SuppressLint("HandlerLeak")
    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case MSG_ENTER:
                    enterAnim();
                    break;
                case MSG_EXIT:
                    if (rlChapterName != null) {
                        rlChapterName.setVisibility(View.GONE);
                    }
                    exitAnim();
                    break;
            }
        }
    };

    @Override
    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
        boolean isNight = SpUtils.getTheme(this);
        if (isNight) {
            setTheme(false);
        }
        selectChoice(position);
    }


    /**
     * 设置补贴模式后的回调
     */
    @Override
    public void setSubSidySucess() {
        setSubSidyState();
        showLoading("");
        presenter.getCatalogue(presenter.getBookId(), UserInstance.getToken(), DeviceUtils.getIMEI(ReaderActivity.this), mPageFactory.getChapterIndex());
        mPageFactory.toSpecifyChapter(mPageFactory.getChapterIndex(), mPageFactory.getChapterIndex());
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(BookContentBean event) {
        setSubSidyState();
        showLoading("");
        mPageFactory.startChapterFromBegin2();
        presenter.clearCache();
        presenter.getCatalogue(presenter.getBookId(), UserInstance.getToken(), DeviceUtils.getIMEI(ReaderActivity.this), mPageFactory.getChapterIndex());
        mPageFactory.toSpecifyChapter(mPageFactory.getChapterIndex(), mPageFactory.getChapterIndex());
    }

    /**
     * 显示补贴模式弹框
     */
    @Override
    public void showSubSidyDialog() {
        if (alertDialog != null) {
            alertDialog.show();
        }
    }

    @Override
    public void isCliable(boolean isCliable) {
//        this.isCliable = isCliable;
    }

    /**
     * 跳转到最新的章节
     */
    @Override
    public void toNewChapter(BookDetailBean bookDetailBean) {
        if (bookDetailBean == null) {
            return;
        }
        initDialog(bookDetailBean);
    }

    @Override
    public void showError(Throwable throwable) {
        ToastUtil.makeShortToast(throwable.getMessage() + "");
    }

    /**
     * 刷新分享时间
     *
     * @param shareTimeBean
     */
    @Override
    public synchronized void refreshShareTime(ShareTimeBean shareTimeBean) {
        PreferenceUtil.getInstance(this).setIsShare(true);
        mNativeTTAdView.setDateShareFlag(true);
        if (0 != shareTimeBean.getEndTime()) {
            PreferenceUtil.getInstance(this).setShareTime(shareTimeBean.getEndTime());
            PreferenceUtil.getInstance(this).setShareDate(DateUtil.getCurrentDate(shareTimeBean.getEndTime()));
        }
        Log.i(TAG, "refreshShareTime: 分享时间" + DateUtil.getCurrentDate(shareTimeBean.getEndTime()));
        shareTime = DateUtils.getDateMin(shareTimeBean.getEndTime());
        if (shareTime > 0 && shareTime <= 20 && mPageFactory.isSubSidyState()) {
            tvTime.setVisibility(View.VISIBLE);
            tvTime.setText("免费看：" + shareTime + "分钟");
        } else {
            tvTime.setVisibility(View.GONE);
        }
        refreshPageView();
    }

    /**
     * 刷新分享时间及更新金币
     *
     * @param bookContentBean
     */
    @Override
    public synchronized void refreshShareTime(BookContentBean bookContentBean) {
        setSubSidyState();
        PreferenceUtil.getInstance(this).setIsShare(bookContentBean.isDateShareFlag());
        PreferenceUtil.getInstance(this).saveSubSidyStateValue(Integer.valueOf(bookContentBean.getReadType()));
        mNativeTTAdView.setDateShareFlag(bookContentBean.isDateShareFlag());
        if (bookContentBean != null && mPageFactory.isSubSidyState()) {
            if (0 != bookContentBean.getEndTime()) {
                shareTime = DateUtils.getDateMin(bookContentBean.getEndTime());
            }
            if (0 != bookContentBean.getEndTime()) {
                PreferenceUtil.getInstance(this).setShareTime(bookContentBean.getEndTime());
                PreferenceUtil.getInstance(this).setShareDate(DateUtil.getCurrentDate(bookContentBean.getEndTime()));
            }
        }
    }

    DecimalFormat decimalFormat = new DecimalFormat("#0.00");

    @Override
    public void refreshAddMoney(ShareTimeBean shareTimeBean) {
        Log.i("章节名", "refreshAddMoney: ");
        tvMoney.setText("今日补贴：¥" + decimalFormat.format(shareTimeBean.getUserPrice()) + "");
        if (0 != shareTimeBean.getAddPrice()) {
            tvAddMoney.setVisibility(View.VISIBLE);
            tvAddMoney.setText("+" + shareTimeBean.getAddPrice());
            tvAddMoney.startAnimation(AnimationUtils.loadAnimation(ReaderActivity.this, R.anim.anim_money));
        }
    }

    @Override
    public void showShareSuccess() {
        if (alertShareDialog != null) {
            alertShareDialog.show();
        }
    }

    @Override
    public Context getViewContext() {
        return this;
    }

    @Override
    public void refresh(List<ChapterItemBean> list) {
        mAdapter.setList(list);
        mSeekBar.setMax(list.size() - 1);
    }


    public boolean isShow() {
        return layoutState == STATE_SHOW;
    }

    public boolean dismissCatalogue() {
        if (mDrawerLayout.isDrawerOpen(mNavigationView)) {
            mDrawerLayout.closeDrawer(mNavigationView);
            return true;
        }
        return false;
    }


    @OnClick({R.id.back_image, R.id.pre_chapter_text, R.id.next_chapter_text, R.id.catalogue_text,
            R.id.day_night_text, R.id.setting_text, R.id.comment_text, R.id.tvSysLight,
            R.id.llTextSpaceAdd, R.id.llTextSpaceMinus, R.id.llTextMinus, R.id.llTextAdd,
            R.id.btn_real_anim, R.id.btn_cover_anim, R.id.btn_slide_anim, R.id.btn_no_anim, R.id.order_btn
            , R.id.rlReadGuide, R.id.ivMore, R.id.tvProtectEye, R.id.tvOtherSwt, R.id.tvSubSidyModel,
            R.id.tvAddShelf})
// R.id.title_layout, R.id.bottom_layout,R.id.setting_parent,
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.back_image:
                addShelfBook();
                break;
            case R.id.pre_chapter_text:
                endProgress = mSeekBar.getProgress();
                mPageFactory.preChapter(false);
                mPageView.refreshCurrPage();
                mPageView.refreshNextPage();
                break;
            case R.id.next_chapter_text:
                endProgress = mSeekBar.getProgress();
                mPageFactory.nextChapter();
                mPageView.refreshCurrPage();
                mPageView.refreshNextPage();
                break;
            case R.id.catalogue_text:
                mDrawerLayout.openDrawer(mNavigationView);
                mAdapter.notifyDataSetChanged();
                dismiss();
                break;
            case R.id.day_night_text:
                switchTheme();
                break;
            case R.id.setting_text:
                dismiss();
                dismissNoAnimation();
                showSettingLayout();
                break;
            case R.id.comment_text:
                if (isNetwork()) {
                    presenter.startToComment();
                }
                break;
            case R.id.tvAddShelf:
                if (isNetwork()) {
                    //加入书架
                    presenter.addToBookShelf(false);
                    v.setVisibility(View.GONE);
                    Toast.makeText(this, getResources().getString(R.string.already_added_in_book_shelf), Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.title_layout:
            case R.id.bottom_layout:
            case R.id.setting_parent:
                break;
            case R.id.llTextSpaceAdd:
                addSpace(SpUtils.getSpaceTimes(this));
                break;
            case R.id.llTextSpaceMinus:
                decSpace(SpUtils.getSpaceTimes(this));
                break;
            case R.id.tvSysLight:
//                int sysProgress = ScreenUtils.getSystemBrightness(this);
//                mLightSeekBar.setProgress((int) ((sysProgress / 255.0f) * 100));
//                ScreenUtils.changeAppBrightness(ReaderActivity.this, sysProgress);
//                SpUtils.setReadLight(this, (int) ((sysProgress / 255.0f) * 100));
                boolean isNightMode = PreferenceUtil.getInstance(this).getIsNightMode();
                isNightMode = !isNightMode;
                Log.i(TAG, "onClick: " + isNightMode);
                PreferenceUtil.getInstance(this).setIsNightMode(isNightMode);
                boolean isSystemBrightness = PreferenceUtil.getInstance(this).getIsSystemBirghtness();
                Log.i(TAG, "onClick:isSystemBrightness= " + isSystemBrightness);
                if (isSystemBrightness) {
                    mLightSeekBar.setEnabled(false);
                    int brightness = ScreenUtils.getSystemBrightness(this);
                    mLightSeekBar.setProgress(brightness - 1);
                    ScreenUtils.setActivityBrightness(this, -1);
                } else {
                    mLightSeekBar.setEnabled(true);
                    int brightness = PreferenceUtil.getInstance(this).getBrightness(this);
                    mLightSeekBar.setProgress(brightness - 1);
                    ScreenUtils.setActivityBrightness(this, brightness);
                }
                tvSysLight.setChecked(isSystemBrightness);
                Log.i(TAG, "onClick: " + tvSysLight.isChecked());
                break;
            case R.id.llTextMinus:
                decTextSize(SpUtils.getTextSize(this, DEFAULT_TEXT_SIZE));
                break;
            case R.id.llTextAdd:
                addTextSize(SpUtils.getTextSize(this, DEFAULT_TEXT_SIZE));
                break;
            case R.id.btn_real_anim:
                long t1 = System.currentTimeMillis();
                if (t1 - et < 1000) {
                    return;
                }
                setAnimation(0, v);
                break;
            case R.id.btn_cover_anim:
                long t2 = System.currentTimeMillis();
                if (t2 - et < 1000) {
                    return;
                }
                setAnimation(1, v);
                break;
            case R.id.btn_slide_anim:
                long t3 = System.currentTimeMillis();
                if (t3 - et < 1000) {
                    return;
                }
                setAnimation(2, v);
                break;
            case R.id.btn_no_anim:
                long t4 = System.currentTimeMillis();
                if (t4 - et < 1000) {
                    return;
                }
                setAnimation(3, v);
                break;
            case R.id.order_btn:
                orderCatalogue();
                break;
            case R.id.rlReadGuide:
                PreferenceUtil.getInstance(this).setReadGuide(false);
                rlReadGuide.setVisibility(View.GONE);
                break;
            case R.id.ivMore:
                PopupWindowView popupWindowView = new PopupWindowView(this);
                popupWindowView.initView(UIHelper.dip2px(this, 154), UIHelper.dip2px(this, 145), -UIHelper.dip2px(this, 10), 0);
                popupWindowView.showPopupWindow(ivMore);
                popupWindowView.setOnPopupWindowClickListener(this);
                break;
            case R.id.tvProtectEye:
//                tvAddMoney.setVisibility(View.GONE);
                if (tvProtectEye.isSelected()) {
                    tvProtectEye.setSelected(false);
                    tvMoney.setTextColor(getResources().getColor(R.color.colorffff7c25));
                } else {
                    tvProtectEye.setSelected(true);
                    tvMoney.setTextColor(getResources().getColor(R.color.colorFF7E2A));
                }
                SpUtils.setProtectEye(this, tvProtectEye.isSelected());
                mPageView.refresh();
                break;
            case R.id.tvOtherSwt:
                Intent intent = new Intent(this, ReadSetActivity.class);
                intent.putExtra("bookId", presenter.getBookId());
                startActivityForResult(intent, Constant.READ_SET_REQUEST_CODE);
                break;
            /**
             * 补贴模式按钮
             */
            case R.id.tvSubSidyModel:
                if (isNetwork()) {
                    if (1 == UserInstance.getLoginData().getIsVipUser()) {
                        ToastUtil.makeShortToast("VIP尊享无广告畅读，无补贴模式");
                        break;
                    }
                    showSubSidyDialog();
                }
                break;
        }
    }

    @Override
    public void onClickPopup(View view) {
        switch (view.getId()) {
            case R.id.rlShare:
                if (mPageFactory.isUnShelf()) {
                    ToastUtil.makeShortToast("书籍已下架");
                    return;
                }
                if (isNetwork()) {
                    presenter.share(false);
                }
                break;
            case R.id.RlYjfk:
                if (isNetwork()) {
                    if (UserInstance.isLogin()) {
                        String nickname = UserInstance.getLoginData().getNickName();
                        if (!TextUtils.isEmpty(nickname)) {
                            FeedbackAPI.setUserNick(nickname);
                        }
                    }
                    FeedbackAPI.openFeedbackActivity();
                }
                break;
            case R.id.RlDetail:
                BookDetailActivity.startDetailActivity(this, presenter.getBookId());
                break;
        }
    }

    private void orderCatalogue() {
        mRecyclerView.post(new Runnable() {
            @Override
            public void run() {
                int visibleChildCount = layoutManager.findLastVisibleItemPosition() - layoutManager.findFirstVisibleItemPosition();
                mAdapter.reverse(mRecyclerView, visibleChildCount);
            }
        });
    }

    private void setAnimation(int index, View v) {
        if (SpUtils.getAnimIndex(this) != index) {
            switch (index) {
                case 0:
                    mPageView.setAnimation(new RealAnimation(this));
                    break;
                case 1:
                    mPageView.setAnimation(new CoverAnimation());
                    break;
                case 2:
                    mPageView.setAnimation(new SlideAnimation());
                    break;
                case 3:
                default:
                    mPageView.setAnimation(new NoAnimation());
                    break;
            }
            selectView(v);
            SpUtils.setAnimIndex(this, index);
        }

    }

    private void addTextSize(int textSize) {
        if (textSize < MAX_TEXT_SIZE) {
            textSize++;
            SpUtils.setTextSize(this, textSize);
            mPageFactory.setTextSize(textSize);
            mPageView.refresh();
        }
    }

    private void decTextSize(int textSize) {
        if (textSize > MIN_TEXT_SIZE) {
            textSize--;
            SpUtils.setTextSize(this, textSize);
            mPageFactory.setTextSize(textSize);
            mPageView.refresh();
        }
    }

    /**
     * 增加行高
     *
     * @param spaceTimes
     */
    private void addSpace(int spaceTimes) {
        if (spaceTimes <= MAX_SPACE_SIZE) {
            spaceTimes += 8;
            SpUtils.setSpaceTimes(this, spaceTimes);
            Log.i(TAG, "addSpace: " + spaceTimes);
            mPageFactory.setSpace(spaceTimes);
            mPageView.refresh();
        }
    }

    private void decSpace(int spaceTimes) {
        if (spaceTimes >= MIN_SPACE_SIZE) {
            spaceTimes -= 8;
            Log.i(TAG, "decSpace: " + spaceTimes);
            SpUtils.setSpaceTimes(this, spaceTimes);
            mPageFactory.setSpace(spaceTimes);
            mPageView.refresh();
        }
    }

    private void selectChoice(int index) {
        readBgAdapter.setSelect(index);
        SpUtils.setBgIndex(this, index);
        mPageView.onBackgroundChange(BG_COLOR[index]);
        mPageView.refresh();
    }

    private void showSettingLayout() {
        ObjectAnimator.ofFloat(mSettingParent, "translationY", 0).setDuration(ANIM_DURATION).start();
        mPageView.setCanPage(false);
    }

    private void dismissSettingLayout() {
        ObjectAnimator.ofFloat(mSettingParent, "translationY", mSettingParent.getLayoutParams().height).setDuration(ANIM_DURATION).start();
    }

    public void show() {
        if (layoutState == STATE_HIDE) {
            mHandler.sendEmptyMessage(MSG_ENTER);
            if (!presenter.isAlreadyAddShelf()) {
                tvAddShelf.setVisibility(View.VISIBLE);
                tvAddShelf.setAnimation(AnimationUtils.loadAnimation(this, R.anim.fade_in));
            }
            mPageView.postDelayed(new Runnable() {
                @Override
                public void run() {
                    changeToNotFullScreen();
                }
            }, 0);
        }
    }

    public void dismiss() {
        if (layoutState == STATE_SHOW) {
            mHandler.sendEmptyMessage(MSG_EXIT);
            if (!presenter.isAlreadyAddShelf()) {
                tvAddShelf.setVisibility(View.GONE);
                tvAddShelf.setAnimation(AnimationUtils.loadAnimation(this, R.anim.fade_out));
            }
            mPageView.postDelayed(new Runnable() {
                @Override
                public void run() {
                    changeToFullScreen();
                }
            }, 0);
        }
    }

    private void dismissNoAnimation() {
        mTitleLayout.setTranslationY(-mTitleLayout.getLayoutParams().height);
        mBottomLayout.setTranslationY(mBottomLayout.getLayoutParams().height);
        layoutState = STATE_HIDE;
    }

    private void setTheme(boolean isNight) {
        if (isNight) {//设置成晚上
            mTitleLayout.setBackgroundColor(getResources().getColor(R.color.color_282828));
            llBottomSet.setBackgroundColor(getResources().getColor(R.color.color_282828));
            mSettingParent.setBackgroundColor(getResources().getColor(R.color.color_282828));
            mNavigationView.setBackgroundColor(getResources().getColor(R.color.color_282828));
            rlChapter.setBackgroundColor(getResources().getColor(R.color.color_282828));
            mBackImage.setImageResource(R.mipmap.ic_read_back_night);
//            mAddShelfImage.setImageResource(R.mipmap.ic_read_add_shelf_night);
            mDayNightText.setCompoundDrawablesWithIntrinsicBounds(null, getResources().getDrawable(R.mipmap.ic_read_night), null, null);
            mDayNightText.setText(R.string.mode_day);
            tvBookTitle.setTextColor(getResources().getColor(R.color.color_999));
            mPageFactory.setTextColor(getResources().getColor(R.color.night_text_color));
            mPageView.onBackgroundChange(getResources().getColor(R.color.reader_bg_night));
//            mSeekBar.setSelected(true);
        } else {
            mTitleLayout.setBackgroundColor(Color.WHITE);
            llBottomSet.setBackgroundColor(Color.WHITE);
            mSettingParent.setBackgroundColor(Color.WHITE);
            mNavigationView.setBackgroundColor(Color.WHITE);
            rlChapter.setBackgroundColor(Color.WHITE);
            mBackImage.setImageResource(R.mipmap.ic_read_back_day);
            mDayNightText.setCompoundDrawablesWithIntrinsicBounds(null, getResources().getDrawable(R.mipmap.ic_read_day), null, null);
            mDayNightText.setText(R.string.mode_night);
            mPageFactory.setTextColor(Color.BLACK);
            mPageView.onBackgroundChange(BG_COLOR[SpUtils.getBgIndex(this)]);
            tvBookTitle.setTextColor(getResources().getColor(R.color.color_333));
        }
        SpUtils.setTheme(this, isNight);
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        MobclickAgent.onPageStart("ReaderActivity");
        mPageView.refreshCurrPage();
        mPageView.refreshNextPage();
    }

    private void switchTheme() {
        boolean isNight = SpUtils.getTheme(this);
        setTheme(!isNight);
        Log.i(TAG, "switchTheme: " + mPageFactory.isRecycled());
        mPageFactory.initPayView();
        Log.i(TAG, "switchTheme: " + mPageFactory.isRecycled());

        mPageFactory.convertBatteryBitmap();
        Log.i(TAG, "switchTheme: " + mPageFactory.isRecycled());
        mPageView.refresh();
    }

    /**
     * @param view 选中View
     */
    private void selectView(View view) {
        ViewParent parent = view.getParent();
        if (parent != null) {
            ViewGroup parentGroup = (ViewGroup) parent;
            for (int i = 1, childCount = parentGroup.getChildCount(); i < childCount; i++) {
                View child = parentGroup.getChildAt(i);
                child.setSelected(false);
            }
        }
        view.setSelected(true);
    }

    /**
     * 进入动画
     */
    private void enterAnim() {
        AnimatorSet set = new AnimatorSet();
        ObjectAnimator topLayoutAnim = ObjectAnimator.ofFloat(mTitleLayout, "translationY", 0);
        ObjectAnimator bottomLayoutAnim = ObjectAnimator.ofFloat(mBottomLayout, "translationY", 0);
        set.play(topLayoutAnim).with(bottomLayoutAnim);
        set.setDuration(ANIM_DURATION);
        set.addListener(new SimpleAnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {
                super.onAnimationStart(animation);
                layoutState = STATE_SHOWING;
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                layoutState = STATE_SHOW;
            }
        });
        set.start();
    }

    /**
     * 进入动画
     */
    private void enterAnim2() {
        AnimatorSet set = new AnimatorSet();
        ObjectAnimator topLayoutAnim = ObjectAnimator.ofFloat(mTitleLayout, "translationY", 0);
        set.play(topLayoutAnim);
        set.setDuration(ANIM_DURATION);
        set.addListener(new SimpleAnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {
                super.onAnimationStart(animation);
                layoutState = STATE_SHOWING;
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                layoutState = STATE_SHOW;
            }
        });
        set.start();
    }

    /**
     * 隐藏动画
     */
    private void exitAnim() {
        AnimatorSet set = new AnimatorSet();
        if (presenter.getChapterList().size() > 0) {
            ObjectAnimator topLayoutAnim = ObjectAnimator.ofFloat(mTitleLayout, "translationY", mTitleLayout.getLayoutParams() == null ? 0 : -mTitleLayout.getLayoutParams().height);
            set.play(topLayoutAnim);
        }
        ObjectAnimator bottomLayoutAnim = ObjectAnimator.ofFloat(mBottomLayout, "translationY", mTitleLayout.getLayoutParams() == null ? 0 : mBottomLayout.getLayoutParams().height);
        set.play(bottomLayoutAnim);
        set.setDuration(ANIM_DURATION);
        set.addListener(new SimpleAnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {
                super.onAnimationStart(animation);
                layoutState = STATE_HIDING;
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                layoutState = STATE_HIDE;
            }
        });
        set.start();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == Constant.START_MULTI_PAY_REQUEST_CODE && resultCode == RESULT_OK) {
            //step1:删除这个章节以及之后一些章节的缓存
            if (data != null) {
                Loading.getInstance().show(getSupportFragmentManager());
//                showLoading();
                Loading.getInstance().setLoadingText("付费成功，加载中...");
//                isCliable = false;
                presenter.removeCacheChangeStatus(data.getIntExtra(Constant.EXTRA_PAY_TYPE, -1));//data.getStringExtra(Constant.EXTRA_CHAPTER_ID),
                // step2:重新获取当前章节内容
                mPageFactory.chapterPaySuccess(true);
            }
            refreshPayView();
//            presenter.reGetCatalogue();
        }
        if (requestCode == Constant.PAY_REQUEST_CODE && resultCode == RESULT_OK) {
//            presenter.getUserInfo(UserInstance.getToken());
            refreshPayView();
        }
        if (requestCode == Constant.READ_SET_REQUEST_CODE && resultCode == RESULT_OK) {
            if (data != null) {
                boolean isCheck = data.getBooleanExtra("isCheck", false);
//                presenter.removeCacheChangeStatus(data.getIntExtra(Constant.EXTRA_PAY_TYPE, -1));//data.getStringExtra(Constant.EXTRA_CHAPTER_ID),
                // step2:重新获取当前章节内容
                if (!presenter.isAutoBuy()) {
                    presenter.setIsAutoBuy(isCheck);
                    mPageFactory.setIsAutoBuy(isCheck);
                    if (isCheck) {
                        if (mPageFactory.isPay()) {
                            return;
                        }
                        mPageFactory.chapterPaySuccess(true);
                    }
                }
//                presenter.checkOrDownLoadChapterContent(presenter.getDesChapterIndex());
//                refreshPayView();
            }
        }
    }

    @Override
    public void onBackPressed() {
        if (mSettingParent.getTranslationY() == 0) {
            dismissSettingLayout();
            return;
        }
        if (dismissCatalogue()) {
            return;
        }
        if (isShow()) {
            dismiss();
            return;
        }
        addShelfBook();
    }

    /**
     * 添加到书架
     */
    public void addShelfBook() {
        if (presenter == null) {
            initPresenter();
        }
        if (!presenter.isAlreadyAddShelf()) {

            CollectionHintFragment fragment = new CollectionHintFragment();
            fragment.addCallback(new CollectionHintFragment.Callback() {
                @Override
                public void onOkButtonClicked() {
                    if (isNetwork()) {
                        presenter.addToBookShelf(true);
                    } else {
                        ReaderActivity.super.finish();
                    }
                }

                @Override
                public void onCancelButtonClicked() {
                    ReaderActivity.super.finish();
                }
            });
            fragment.show(getSupportFragmentManager(), "CollectionHintFragment");

            
//            new CollectionHintFragment(new CollectionHintFragment.Callback() {
//                @Override
//                public void onOkButtonClicked() {
//                    if (isNetwork()) {
//                        presenter.addToBookShelf(true);
//                    } else {
//                        ReaderActivity.super.finish();
//                    }
//                }
//
//                @Override
//                public void onCancelButtonClicked() {
//                    ReaderActivity.super.finish();
//                }
//            }).show(getSupportFragmentManager(), "CollectionHintFragment");
        } else {
            super.finish();
            overridePendingTransition(R.anim.anim_no, R.anim.anim_detail_exit);
        }
    }

    long et = 0;

    /**
     * 音量键翻页(原来源码中，声音处理在onKeyUp中，而音量控件的显示与否在哦那onKeyDown中，故还需要重写onKeyDown方法)
     */
    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        long t1 = System.currentTimeMillis();
        if (t1 - et < 800) {
            return false;
        }
        et = t1;
        mAdapter.setSelectedItem(mPageFactory.getChapterIndex());
        if (presenter.getDesChapterIndex() != 0) {
            mSeekBar.setProgress(presenter.getDesChapterIndex());
        }
        mPageView.setCanPage(true);

        /**
         * 音量键 下键；
         */
        if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {

//            if (SettingManager.getInstance().isVolumeFlipEnable()) {
            /**
             * 判断是否有音量键设置
             */
            if (PreferenceUtil.getInstance(ReaderActivity.this).getVolumeState()) {
//                mPageView.nextPage();
                //触发翻页事件
                mPageView.onTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, ScreenUtils.getScreenWidth() * 3 / 4, ScreenUtils.getScreenHeight() / 10, 0));
                mPageView.onTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, ScreenUtils.getScreenWidth() * 3 / 4, ScreenUtils.getScreenHeight() / 10, 0));
            }
            return true;// 防止翻页有声音
//            }
        } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
            if (PreferenceUtil.getInstance(ReaderActivity.this).getVolumeState()) {
//                mPageView.prePage();
                //触发翻页事件
                mPageView.onTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, ScreenUtils.getScreenWidth() / 4, ScreenUtils.getScreenHeight() / 10, 0));
                mPageView.onTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, ScreenUtils.getScreenWidth() / 4, ScreenUtils.getScreenHeight() / 10, 0));

            }
            return true;
        }
        return super.onKeyUp(keyCode, event);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_VOLUME_DOWN:
//                if (SettingManager.getInstance().isVolumeFlipEnable()) {
                return true;
//                }
            case KeyEvent.KEYCODE_VOLUME_UP:
//                if (SettingManager.getInstance().isVolumeFlipEnable()) {
                return true;
//                }
        }
        return super.onKeyDown(keyCode, event);
    }

    /**
     * 从BookDetail启动，如果在BookDetail中发现有阅读历史或者收藏，调用的是下面两个方法，如果没有收藏和历史调用该方法
     */
    public static void startActivity(Activity context, BookDetailBean bookDetailBean,
                                     boolean isToNewChapter) {
        Intent intent = new Intent(context, ReaderActivity.class);
        intent.putExtra(Constant.EXTRA_BOOK_DETAIL_BEAN, bookDetailBean);
        intent.putExtra(Constant.EXTRA_TO_NEW_CHAPTER, isToNewChapter);
        intent.putExtra(EXTRA_TO_READER_FROM, Constant.START_FROM_BOOK_DETAIL);
        context.startActivity(intent);
        startByAnimation(context);
    }

    /**
     * 从书架启动
     */
    public static void startActivity(Context context, BookCollection bookCollection) {
        Intent intent = new Intent(context, ReaderActivity.class);
        intent.putExtra(Constant.EXTRA_COLLECTION_BEAN, bookCollection);
        intent.putExtra(EXTRA_TO_READER_FROM, Constant.START_FROM_COLLECTION);
        intent.putExtra(EXTRA_TO_ISJPUSH, false);
        context.startActivity(intent);
        startByAnimation((Activity) context);
    }

    /**
     * 从激光推送进入
     */
    public static void startActivity(Context context, BookCollection bookCollection, boolean isCollection, boolean isJush) {
        Intent intent = new Intent(context, ReaderActivity.class);
        intent.putExtra(Constant.EXTRA_COLLECTION_BEAN, bookCollection);
        intent.putExtra(EXTRA_TO_READER_FROM, Constant.START_FROM_COLLECTION);
        intent.putExtra("isCollection", false);
        intent.putExtra(EXTRA_TO_ISJPUSH, isJush);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
//        startByAnimation((Activity) context);
    }

    /**
     * 从书架启动
     */
    public static void startActivity(Context context, BookCollection bookCollection,
                                     boolean isCollection) {
        Intent intent = new Intent(context, ReaderActivity.class);
        intent.putExtra(Constant.EXTRA_COLLECTION_BEAN, bookCollection);
        intent.putExtra(EXTRA_TO_READER_FROM, Constant.START_FROM_COLLECTION);
        intent.putExtra("isCollection", isCollection);
        intent.putExtra(EXTRA_TO_ISJPUSH, false);
        context.startActivity(intent);
        startByAnimation((Activity) context);
    }

    /**
     * 从观看历史启动
     */
    public static void startActivity(Context context, ReaderHistory readerHistory) {
        Intent intent = new Intent(context, ReaderActivity.class);
        intent.putExtra(Constant.EXTRA_READ_HISTORY_BEAN, readerHistory);
        intent.putExtra(EXTRA_TO_READER_FROM, Constant.START_FROM_READ_HISTORY);
        context.startActivity(intent);
        startByAnimation((Activity) context);
    }

    /**
     * 从目录启动
     */
    public static void startActivity(Activity context, ChapterItemBean chapterItemBean, String
            lastChapterName) {
        Intent intent = new Intent(context, ReaderActivity.class);
        intent.putExtra(Constant.EXTRA_CHAPTER_ITEM_BEAN, chapterItemBean);
        intent.putExtra(Constant.EXTRA_CATALOGUE_LAST_CHAPTER, lastChapterName);
        intent.putExtra(EXTRA_TO_READER_FROM, Constant.START_FROM_CATALOGE);
        context.startActivity(intent);
        startByAnimation(context);
    }

    private static void startByAnimation(Activity context) {
        context.overridePendingTransition(R.anim.anim_detail_enter, R.anim.anim_no);
    }

    @Override
    protected void onStart() {
        super.onStart();
        if (isCollection) {
            new CountDownTimer(3000, 1000) {
                @Override
                public void onTick(long millisUntilFinished) {
                }

                @Override
                public void onFinish() {
                    bookCollection.setRemove(1);
                    Log.i("HomeBookShelfFragment", "onFinish:!!! ");
                    EventBus.getDefault().post(bookCollection);
                }
            }.start();

        }
    }

    public void onResume() {
        super.onResume();
        System.gc();
        if (NetworkUtils.isNetworkConnected(this)) {
            changeToNotFullScreen();
            MobclickAgent.onPageStart("ReaderActivity"); //统计页面(仅有Activity的应用中SDK自动调用，不需要单独写。"SplashScreen"为页面名称，可自定义)
            setSubSidyState();
            shareTime = DateUtils.getDateMin(PreferenceUtil.getInstance(this).getShareTime());
            /**
             * 判断分享时间
             */
            if (0 < shareTime && shareTime <= 20 && mPageFactory.isSubSidyState()) {
                tvTime.setVisibility(View.VISIBLE);
                tvTime.setText("免费看：" + shareTime + "分钟");
            } else {
                tvTime.setVisibility(View.GONE);
            }
        } else {
            enterAnim2();
            Log.i(TAG, "setSubSidyState:1 " + mTitleLayout.getVisibility());
        }
    }

    public void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd("ReaderActivity"); // （仅有Activity的应用中SDK自动调用，不需要单独写）保证 onPageEnd 在onPause 之前调用,因为 onPause 中会保存信息。"SplashScreen"为页面名称，可自定义
        if (mPageFactory != null) {
            mPageFactory.saveHistoryAndCollection();
        }
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);

        int from = getIntent().getIntExtra(Constant.EXTRA_TO_READER_FROM, Constant.START_FROM_BOOK_DETAIL);
        if (from == Constant.START_FROM_BOOK_DETAIL) {
            bookDetailBean = (BookDetailBean) getIntent().getParcelableExtra(Constant.EXTRA_BOOK_DETAIL_BEAN);
            if (bookDetailBean == null) {
                Log.e(TAG, "bookDetailBean is null");
                return;
            }
            if (presenter != null) {
                presenter.setOnNewIntent(this, this, bookDetailBean,
                        getIntent().getBooleanExtra(Constant.EXTRA_TO_NEW_CHAPTER, false));
            } else {
                presenter = new ReaderPresenter(this, this, bookDetailBean,
                        getIntent().getBooleanExtra(Constant.EXTRA_TO_NEW_CHAPTER, false));
            }

        } else if (from == Constant.START_FROM_CATALOGE) {
            if (presenter != null) {
                presenter.setOnNewIntent(this, this, (ChapterItemBean) getIntent().getParcelableExtra(Constant.EXTRA_CHAPTER_ITEM_BEAN), getIntent().getStringExtra(Constant.EXTRA_CATALOGUE_LAST_CHAPTER));
            } else {
                presenter = new ReaderPresenter(this, this, (ChapterItemBean) getIntent().getParcelableExtra(Constant.EXTRA_CHAPTER_ITEM_BEAN), getIntent().getStringExtra(Constant.EXTRA_CATALOGUE_LAST_CHAPTER));
            }
        }
        if (presenter.getChapterList().size() == 0) {
            Loading.getInstance().setView(2);
            Loading.getInstance().show(getSupportFragmentManager());
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mPageFactory != null) {
            mPageFactory.recycle();
            mPageFactory = null;
        }
        animation.onDestory();
        if (presenter != null) {
            presenter.recycle();
            presenter = null;
        }
        unregisterReceiver(receiver);
        if (mNativeTTAdView != null) {
            mNativeTTAdView.onDestory();
        }
        if (countDownTimer != null) {
            countDownTimer.onFinish();
        }

        if (alertDialogProgress != null) {
            alertDialogProgress.dismiss();
        }
        if (alertShareDialog != null) {
            alertShareDialog.dismiss();
        }
        if (alertDialog != null) {
            alertDialog.dismiss();
        }
        if (mHandler != null) {
            mHandler.removeCallbacksAndMessages(null);
        }
        if (mPayChapterView != null) {
            mPayChapterView = null;
        }
        if (mPageView != null) {
            mPageView.getDrawingCache().recycle();
        }

        if (fastScroller != null) {
            fastScroller = null;
        }
        dismissLoading();
        EventBus.getDefault().unregister(this);
        mPageView = null;
        setContentView(R.layout.activity_null);
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        changeToFullScreen();

    }

    /**
     * 将事件费掉
     *
     * @param v
     * @param event
     * @return
     */
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        switch (v.getId()) {
            case R.id.tvMoney:

                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    if (!NetworkUtils.isNetworkConnected(this)) {
                        ToastUtil.makeShortToast("网络异常");
                        break;
                    }
                    SubSidyActivity.start(ReaderActivity.this);
                }
                break;
            case R.id.tvOpenSubSidy:
                if (1 == UserInstance.getLoginData().getIsVipUser()) {
                    ToastUtil.makeShortToast("VIP尊享无广告畅读，无补贴模式");
                    break;
                }
                if (alertDialog != null) {
                    alertDialog.show();
                }
                break;
        }
        return true;
    }

    /**
     * 电池状态、系统时间广播
     */
    class Receiver extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {
            if (mPageFactory != null) {
                if (Intent.ACTION_BATTERY_CHANGED.equals(intent.getAction())) {
                    int level = intent.getIntExtra("level", 0);
                    mPageFactory.setBattery(level);
                    if (mPageFactory.isSubSidyState()) {
                        shareTime = DateUtils.getDateMin(PreferenceUtil.getInstance(ReaderActivity.this).getShareTime());
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                if (shareTime > 0 && shareTime <= 20 && mPageFactory.isSubSidyState()) {
                                    tvTime.setVisibility(View.VISIBLE);
                                    tvTime.setText("免费看：" + shareTime + "分钟");
                                } else {
                                    tvTime.setVisibility(View.GONE);
                                }
                            }
                        });
                    } else {
                        tvTime.setVisibility(View.GONE);
                    }
                } else if (Intent.ACTION_TIME_TICK.equals(intent.getAction())) {
                }
                if (mPageView != null) {
                    mPageView.refresh();
                }
            }
        }
    }

    private CatalogueAdapter mAdapter = new CatalogueAdapter(new OnItemClickListener() {
        @Override
        public void onItemClicked(RecyclerView.Adapter adapter, View itemView, int index) {
            //dismiss drawLayout
//            PreferenceUtil.getInstance(ReaderActivity.this).saveAdValue(presenter.getBookId(), 1001);
            dismissCatalogue();//
            mPageFactory.startChapterFromBegin();
            showLoading("");
            mPageFactory.toSpecifyChapter(index, false);
            mPageView.refreshCurrPage();
            mPageView.refreshNextPage();
            LinearLayoutManager layoutManager = (LinearLayoutManager) mRecyclerView.getLayoutManager();
            int visibleChildCount = 0;
            if (layoutManager != null) {
                visibleChildCount = layoutManager.findLastVisibleItemPosition() - layoutManager.findFirstVisibleItemPosition();
            }

            //设置适配器选中的目标
            mAdapter.setSelectedItem(index);

            mRecyclerView.scrollToPosition(Math.min(index + visibleChildCount - 1, presenter.getChapterNum() - 1));
            if (0 < shareTime && shareTime <= 20 && mPageFactory.isSubSidyState()) {
                tvTime.setVisibility(View.VISIBLE);
                tvTime.setText("免费看：" + shareTime + "分钟");
            } else {
                tvTime.setVisibility(View.GONE);
            }
        }
    });


    /**
     * 显示阅读进度不同的弹框
     */
    private void initDialog(BookDetailBean bookDetailBean) {
        View view = LayoutInflater.from(this).inflate(R.layout.dialog_chapter, null);
        TextView tvCancel = view.findViewById(R.id.tvCancel);
        TextView tvContent = view.findViewById(R.id.tvContent);

        int chapterNum = (100 * (bookDetailBean.getChapterIndex() + 1) / (presenter.getChapterList().size() + 1));
        if (presenter.getChapterList().size() == 0) {
            return;
        }
        String content = "检测您上次阅读到" + chapterNum + "%：" + bookDetailBean.getChapterName() + "，是否跳转到最新章节的进度？";
        tvContent.setText(content);
        TextView tvOk = view.findViewById(R.id.tvOk);
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setView(view);

        alertDialogProgress = builder.create();
        tvOk.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (alertDialogProgress.isShowing()) {
                    alertDialogProgress.dismiss();
                }
//                mPageFactory.toSpecifyChapter(bookDetailBean.getChapterIndex(), 0);
                mPageFactory.startChapterFromBegin();
                mPageFactory.toSpecifyChapter(bookDetailBean.getChapterIndex(), false);
                mPageView.refresh();
            }
        });
        tvCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (alertDialogProgress.isShowing()) {
                    alertDialogProgress.dismiss();
                }
            }
        });
        alertDialogProgress.show();
    }

    /**
     * 补贴模式的弹窗
     */
    private void initDialog() {
        if (view == null) {
            view = LayoutInflater.from(this).inflate(R.layout.dialog_subsidy, null);
            tvDialogTitle = view.findViewById(R.id.tvDialogTitle);
            tvOk = view.findViewById(R.id.tvOk);
            llExit = view.findViewById(R.id.llExit);
            tvCancelExit = view.findViewById(R.id.tvCancelExit);
            tvContent = view.findViewById(R.id.tvContent);
            tvOkExit = view.findViewById(R.id.tvOkExit);
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setCancelable(false);
        builder.setView(view);
        tvOk.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                presenter.setSubSidy(0);
                mPageFactory.startChapterFromBegin2();
                presenter.clearCache();
                if (alertDialog.isShowing()) {
                    alertDialog.dismiss();
                }
            }
        });
        tvCancelExit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (alertDialog.isShowing()) {
                    alertDialog.dismiss();
                }
            }
        });
        tvOkExit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mPageFactory.startChapterFromBegin2();
                presenter.clearCache();
                presenter.setSubSidy(2);
                if (alertDialog.isShowing()) {
                    alertDialog.dismiss();
                }
            }
        });
        alertDialog = builder.create();
    }

    /**
     * 设置补贴模式的布局显示及样式
     */
    @Override
    public void setSubSidyState() {
        if (!isNetwork()) {
            rlSubSidy.setVisibility(View.GONE);
            tvSubSidyModel.setVisibility(View.GONE);
            return;
        }
        Log.i("补贴状态", "setSubSidyState: " + PreferenceUtil.getInstance(this).getSubSidyStateValue());
        if (0 == PreferenceUtil.getInstance(this).getSubSidyStateValue()) {
            tvMoney.setVisibility(View.VISIBLE);
            tvOpenSubSidy.setVisibility(View.GONE);
            tvSubSidyModel.setText("退出补贴模式");
            tvDialogTitle.setText("确定退出补贴模式？");
            tvSubSidyModel.setSelected(true);
            tvSubSidyModel.setVisibility(View.VISIBLE);
            rlSubSidy.setVisibility(View.VISIBLE);
            tvOk.setVisibility(View.GONE);
            llExit.setVisibility(View.VISIBLE);

            tvContent.setText("退出补贴模式后,VIP章节恢复收费哦");
        } else if (2 == PreferenceUtil.getInstance(this).getSubSidyStateValue()) {
            tvMoney.setVisibility(View.GONE);
            tvOpenSubSidy.setVisibility(View.VISIBLE);
            tvSubSidyModel.setText("开启补贴模式");
            tvDialogTitle.setText("您已开启补贴模式");
            tvSubSidyModel.setSelected(false);
            tvSubSidyModel.setVisibility(View.VISIBLE);
            rlSubSidy.setVisibility(View.VISIBLE);
            tvOk.setVisibility(View.VISIBLE);
            llExit.setVisibility(View.GONE);
            tvContent.setText("如想关闭补贴模式，请在阅读页点击屏幕中央，选择设置 > 点击[退出补贴模式]按钮，进行关闭");
        } else {
            rlSubSidy.setVisibility(View.GONE);
            tvSubSidyModel.setVisibility(View.GONE);
        }
        if (1 == UserInstance.getLoginData().getIsVipUser()) {
            rlSubSidy.setVisibility(View.GONE);
            tvSubSidyModel.setVisibility(View.GONE);
        }
    }

    /**
     * 分享成功后的提示
     */
    private void initShareDialog() {
        View view = LayoutInflater.from(this).inflate(R.layout.dialog_reader, null);
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setView(view);
        alertShareDialog = builder.create();
        view.findViewById(R.id.tvKnow).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (alertShareDialog.isShowing()) {
                    alertShareDialog.dismiss();
                }
            }
        });

    }
}
